﻿using Microsoft.AspNetCore.DataProtection.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace WebApp
{
    public class CustomXmlRepository : IXmlRepository
    {
        /// <summary>
        /// 设置MachineKey这里的内容就是复制出xml文件的内容
        /// </summary>
        private readonly string keyContent =
        @"<?xml version='1.0' encoding='utf-8'?><key id='ec2f4123-024e-42c4-801a-eead381471ff' version='1'><creationDate>2021-05-26T01:36:48.0978936</creationDate><activationDate>2021-05-26T01:36:48.0376831</activationDate><expirationDate>2021-08-24T01:36:48.0376831</expirationDate><descriptor deserializerType='Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'>&lt; descriptor &gt; <encryption algorithm='AES_256_CBC' /><validation algorithm='HMACSHA256' /><masterKey p4:requiresEncryption='true' xmlns:p4='http://schemas.asp.net/2015/03/dataProtection'><value>R+gAHFQaVVR78TBq+0pUmXi9l4jcLfyRFNclK7FDCSYzmUFqfU5SbXeI4VYfzMGvpsLtJt2zNdZ9jdPnehNbXw==</value></masterKey></descriptor></key>";

        public virtual IReadOnlyCollection<XElement> GetAllElements()
        {
            return GetAllElementsCore().ToList().AsReadOnly();
        }

        private IEnumerable<XElement> GetAllElementsCore()
        {
            yield return XElement.Parse(keyContent);
        }
        public virtual void StoreElement(XElement element, string friendlyName)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            StoreElementCore(element, friendlyName);
        }

        private void StoreElementCore(XElement element, string filename)
        {
        }
    }
}
